/**
 * CS575 Software Design
 * Group 6
 * Group Members: Anthony Davidson, Kendra Scheesley, Lyndsey Whitman, Stephen Zakrewsky
 * Date: May 19, 2012
 * Main Author(s): Stephen Zakrewsky
 */
package edu.drexel.cs575.a3;

import java.util.HashMap;
import java.util.Map;

public abstract class UnitConverter
{

	/*
	 * This is a static map for now.  In the future it can
	 * be populated by the system, or read from a configuration
	 * file.
	 */
	private static Map<Units, UnitConverter> unitToStrategyMap = new HashMap<Units, UnitConverter>();
	static {
		unitToStrategyMap.put(Units.GRAMS, new GramConverter());
		unitToStrategyMap.put(Units.OUNCES, new OunceConverter());
		unitToStrategyMap.put(Units.POUNDS, new PoundConverter());
	}
	
	public abstract double convertWeight(double weight);
	
	public static UnitConverter getInstanceForUnit(Units unit) {
		UnitConverter unitConverter = unitToStrategyMap.get(unit);
		if(unitConverter == null) {
			throw new IllegalStateException("Unit Converter is not Configured");
		}
		return unitConverter;
	}
	
}
